package com.ruirenyun.util.common;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author Deng Ye
 * @version 1.0
 * @date 2020/11/5
 * @description
 * @modifiedBy
 */
public class YearListUtil {

    public static List<String> getYearList(Date date) {
        ArrayList<String> list = new ArrayList<>();
        Calendar instance = Calendar.getInstance();
        if(Objects.isNull(date)){
            date = new Date();
        }
        instance.setTime(date);
        int year = instance.get(Calendar.YEAR);
        instance.setTime(new Date());
        int nowYear = instance.get(Calendar.YEAR);

        if (year >= nowYear) {
            list.add(nowYear + "");
        } else {
            while (nowYear >= year) {
                list.add(nowYear-- + "");
            }
        }
        return list;
    }
}
